import Vue from 'vue'
import App from './App'
//
import http from '@/utils/request'
import store from '@/store/index'
Vue.prototype.$http = http
// 导入 message.js 模块
import { showMessage } from '@/utils/message'
Vue.prototype.$msg = showMessage
//
Vue.config.productionTip = false

App.mpType = 'app'

function isPromise(obj) {
  return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function'
}

uni.addInterceptor({
  returnValue(res) {
    if (!isPromise(res)) {
      return res
    }
    return new Promise((resolve, reject) => {
      res.then((res) => {
        if (res[0]) {
          reject(res[0])
        } else {
          resolve(res[1])
        }
      })
    })
  },
})

const app = new Vue({
  ...App,
  store,
})
app.$mount()
